import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
    path: '/',
    redirect: '/allrouter/statistics',
  },
  {
    path: '/menhu',
    name: 'Menhu',
    component: () => import('../views/Menhu.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/allrouter',
    name: 'Allrouter',
    component: () => import('../views/Allrouter.vue'),
    // 设置路由元信息
    //  meta: {
    //   requireAuth: true
    // },
    children: [{
        path: '/allrouter/about',
        name: 'About',
        component: () => import('../views/About.vue')
      },
      {
        path: '/allrouter/index',
        name: 'Index',
        component: () => import('../views/Index.vue')
      },
      {
        path: '/allrouter/statistics',
        name: 'Statistics',
        component: () => import('../views/Statistics.vue')
      },

    ],
  }
]

const router = new VueRouter({
  mode: 'history',
  // base: process.env.BASE_URL,
  routes
})

// 设置路由拦截
// router.beforeEach((to, from, next) => {
//   let token = sessionStorage.getItem('token')
//   if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
//     //判断本地是否存在access_token
//     if (token) {
//       next();
//     } else {
//       next('/login');
//     }
//   } else {
//     next();
//   }
// });
export default router